package org.loujiarong.yugioh.util;

import org.loujiarong.yugioh.gameplay.card.Card;
import org.loujiarong.yugioh.gameplay.card.DummyCard;
import org.loujiarong.yugioh.gameplay.duel.Player;
import org.loujiarong.yugioh.util.GameConstants.CardPosition;

public class Command {
	public static final String STARTDUEL = "s";
	public static final String FIRSTTOGO = "f";
	public static final String PLAYERA = "p1";
	public static final String PLAYERB = "p2";
	public static final String YES = "y";
	public static final String NO = "n";
	public static final String CANCEL = "c";
	public static final String HAND = "h";
	public static final String GRAVEYARD = "g";
	public static final String REMOVEDFROMPLAY = "r";
	public static final String MONSTERZONE = "m";
	public static final String SPELLTRAPZONE = "st";
	
	public static Card parseSelectCardCmd(String cmd, Player player) {
		Card card = null;
		String[] para = cmd.split(" ");
		try {
			if(para[0].equals(Command.HAND)) {
				int n = Integer.parseInt(para[1]);
				card = player.getHand().getCard(n);
			}
			if(para[0].equals(Command.GRAVEYARD)) {
				int n = Integer.parseInt(para[1]);
				card = player.getGraveYard().getCard(n);
			}
			if(para[0].equals(Command.REMOVEDFROMPLAY)) {
				int n = Integer.parseInt(para[1]);
				card = player.getRemovedFromPlayArea().getCard(n);
			}
			if(para[0].equals(Command.MONSTERZONE)) {
				int n = Integer.parseInt(para[1]);
				card = player.getField().getMonsterZone()[n];
				if(card == DummyCard.getDummyCard())
					return null;
			}
			if(para[0].equals(Command.SPELLTRAPZONE)) {
				int n = Integer.parseInt(para[1]);
				card = player.getField().getSpellTrapZone()[n];
				if(card == DummyCard.getDummyCard() || 
						card.getPos() == CardPosition.FACE_DOWN ||
						card.getPos() == CardPosition.FACE_DOWN_ATTACK)
					return null;
			}
		} catch(Exception ex) {
			ex.printStackTrace();
			return null;
		}		
		return card;
	}
}
